package com.star.platforms.netty;


import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

public class NettyHelper {

    /**
     * 推送给指定用户
     */
    public void pushToUser(String userId, String msg) {
        Channel userChannel = NettyConfig.getUserChannelMap().get(userId);
        if (userChannel != null) {
            userChannel.writeAndFlush(new TextWebSocketFrame(msg));
        }
    }

    /**
     * 推送给所有用户
     */
    public void pushToAll(String msg) {
        NettyConfig.getChannelGroup().writeAndFlush(new TextWebSocketFrame(msg));
    }

    /**
     * 获取当前连接数
     */
    public int getCurrentConnectCount() {
        return NettyConfig.getChannelGroup().size();
    }
}
